﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Trademark.Interfaces;
using AMS.DataAccess.Trademark.Filters;
using AMS.DataAccess.Trademark.BO.Enums;
using AMS.DataAccess.Trademark.BO;
using AMS.DataAccess.Filter;

public partial class RecvFile_Default : BaseWorkPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnDelete.Attributes["onclick"] = "if(!preCheckDeleteItems('" + gv.ClientID + "')){return false; event.cancelBubble = true;}";
            DoDataBind();
        }
    }

    #region Data Bind
    void DoDataBind()
    {
        int total;
        IRecvFileManager mgr = ManagerFactory.CreateRecvFileManager();
        RecvFileFilter filter = ucSearchRecvFile1.GetRecvFileFilter();
        List<RecvFileInfo> rfList = mgr.GetPagedRecvFiles(CallContext, filter, pager.CurrentPageIndex, pager.PageSize, true, out total);
        gv.DataSource = rfList;
        gv.DataKeyNames = new string[] { "AID" };
        gv.DataBind();
        BindPagers(total);
        lblTotal.Text = total.ToString();
    }

    private void BindPagers(int total)
    {
        pager.RecordCount = total;
        pager2.RecordCount = total;
    }

    protected string FormateDateTime(object value)
    {
        return Utils.FormateDateTime(value, false);
    }

    protected string FormateDateTime(object value, bool showTime)
    {
        return Utils.FormateDateTime(value, showTime);
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        pager2.CurrentPageIndex = pager.CurrentPageIndex;
        DoDataBind();
    }

    protected void pager2_PageChanged(object sender, EventArgs e)
    {
        pager.CurrentPageIndex = pager2.CurrentPageIndex;
        DoDataBind();
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DoDataBind();
    }
    #endregion

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        //ICustomerManager customerMgr = ManagerFactory.CreateCustomerManager();
        //List<int> customerIds = new List<int>();
        //foreach (GridViewRow row in gv.Rows)
        //{
        //    CheckBox chk = row.FindControl("chk") as CheckBox;
        //    if (chk != null && chk.Checked)
        //    {
        //        string sid = gv.DataKeys[row.RowIndex].Value.ToString();
        //        customerIds.Add(int.Parse(sid));
        //    }
        //}

        //if (customerIds.Count > 0)
        //{
        //    int count = customerMgr.DeleteCustomer(CallContext, customerIds.ToArray());
        //    MsgInfo(string.Format("已删除{0}条记录。", count));
        //    DoDataBind();
        //}
        //else
        //{
        //    MsgInfo("未选中记录。");
        //}
    }

    protected void ucSearchRF_OnRecvFileFiltered(object sender, EventArgs e)
    {
        DoDataBind();
    }

}
